import React from 'react'

export default function UseStateFun() {
    const [count,setCount] = React.useState(0)
    const [arrayRes, setArrayRes] = React.useState([1,25])
    function add() {
        //setCount(count+1) //第一种写法
        setCount(count => count+1 )        
    }
    function addArrayItem() {
        setArrayRes(arrayRes => [...arrayRes,8])
    }
    return (
        <div>
            <button className='returnButton'><a href="/">点击返回主菜单</a></button>
            <h1>useStateFun</h1>
            <p>当前求和为{count}</p>
            <button onClick={add}>点击加1</button>
            <ul>
                {
                    arrayRes.map((item,index)=>{
                        return <li key={index}>{item}</li>
                    })
                }
            </ul>
            <button onClick={addArrayItem}>点击修改数组内容</button>
        </div>
    )
}
